package me.imli.app.ui.adapter;

import me.imli.app.R;
import me.imli.app.model.RssItemModel;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

@EBean
public class RssItemAdapter extends IBaseAdapter<RssItemModel> {
	
	@RootContext
	Context mContext;
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (convertView == null) {
			holder = new Holder();
			convertView = LinearLayout.inflate(mContext, R.layout.item_rss, null);
			findView(holder, convertView);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		setView(holder, getItem(position));
		return convertView;
	}

	private void findView(Holder holder, View view) {
		holder.tvTitle = (TextView) view.findViewById(R.id.tv_item_rss_title);
		holder.tvDescription = (TextView) view.findViewById(R.id.tv_item_rss_description);
	}

	private void setView(Holder holder, RssItemModel model) {
		if (model == null) return;
		if (model.title != null) holder.tvTitle.setText(model.title);
//		if (model.description != null) holder.tvDescription.setText(model.description);
	}

	class Holder extends IBaseHolder {
		public TextView tvTitle;
		public TextView tvDescription;
	}
}
